﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Diagnostics;

namespace TinyEngineEditor
{
    public class ApplicationSettings
    {
        public static ApplicationSettings Instance;
        static ApplicationSettings()
        {
            Instance = new ApplicationSettings();
        }
        
        public static void Load()
        {
            if (File.Exists(filename))
            {
                Trace.WriteLine("Loading application settings");

                var ser = new XmlSerializer(typeof(ApplicationSettings));
                using (var reader = new StreamReader(filename))
                {
                    var obj = ser.Deserialize(reader);
                    Instance = obj as ApplicationSettings;
                }
            }
        }

        public static void Save()
        {
            Trace.WriteLine("Saving application settings");
            var ser = new XmlSerializer(typeof(ApplicationSettings));
            using (var writer = XmlWriter.Create(filename))
            {
                ser.Serialize(writer, Instance);
            }
        }

        const string filename = "appSettings.settings";
    }
}
